from marshmallow import Schema, fields, pre_load, ValidationError
import time

class NodeRebootSchema(Schema):
    start_time = fields.Float(required=False)
    end_time = fields.Float(required=False)

    @pre_load
    def validate_timestamp(self, data, **kwargs):
        if len(data) == 1:
            raise ValidationError(
                'Input data must have both start_time and end_time or none', "args validation"
            )

        if len(data) == 0:
            out = {}
            out['start_time'] = time.time() * 1000
            out['end_time'] = time.time() * 1000
            return out

        return data